package cn.tedu.staff_user.management.controller;

import cn.tedu.common.web.JsonResult;
import cn.tedu.staff_user.management.pojo.entity.User;
import cn.tedu.staff_user.management.pojo.param.StaffAddNewParam;
import cn.tedu.staff_user.management.pojo.param.StaffUpdateParam;
import cn.tedu.staff_user.management.pojo.param.UserAddNewParam;
import cn.tedu.staff_user.management.pojo.param.UserUpdateParam;
import cn.tedu.staff_user.management.pojo.vo.StaffListItemVO;
import cn.tedu.staff_user.management.pojo.vo.UserListItemVO;
import cn.tedu.staff_user.management.service.IStaffService;
import cn.tedu.staff_user.management.service.IUserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "2.用户管理")
@RestController
@RequestMapping("/userManagemant")
public class UserController {

    @Autowired
    private IUserService UserService;

    @GetMapping("")
    @ApiOperation("用户列表")
    @ApiOperationSupport(order = 400)
    public JsonResult list(){

//        List<UserListItemVO> list = UserService.list();
        List<User> list = UserService.list();

        return JsonResult.ok(list);
    }

    @PostMapping("/add-new")
    @ApiOperation("添加用户")
    @ApiOperationSupport(order = 410)
    public JsonResult addNew(UserAddNewParam userAddNewParam){
        UserService.addNew(userAddNewParam);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/delete")
    @ApiOperation("删除用户")
    @ApiOperationSupport(order = 420)
    public JsonResult deleteById(@PathVariable Long id){
        UserService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("更新用户")
    @ApiOperationSupport(order = 420)
    public JsonResult updateById(Long id,UserUpdateParam userUpdateParam){
        UserService.updateById(id,userUpdateParam);
        log.error(userUpdateParam+"**********************");
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/enable")
    @ApiOperation("启用类别")
    @ApiOperationSupport(order = 430)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "long")
    })
    public JsonResult setEnable(@PathVariable @Range(min = 1, message = "请提交有效的类别ID值！") Long id) {
        UserService.setEnable(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/disable")
    @ApiOperation("禁用类别")
    @ApiOperationSupport(order = 440)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "long")
    })
    public JsonResult setDisable(@PathVariable @Range(min = 1, message = "请提交有效的类别ID值！") Long id) {
        UserService.setDisable(id);
        return JsonResult.ok();
    }



}
